#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long ll;
using namespace std;

int main()
{
	int n;
	while (cin >> n)
	{
		int t = n;
		int cnt = 1; 
		while (t >= 2)
		{
			t /= 2;
			n -= cnt;
			cnt *= 2;
		}
		cout << n * 2 - 1 << "\n"; 
	}

	return 0;
}
